package com.spring.demo.publicutil.thread;

import com.spring.demo.entity.Person;

import java.util.concurrent.TimeUnit;

/**
 * 实现循环输出
 * @author youjc
 * @date 2021年04月18日 10:00
 */
public class T09_ThreadLocal9 {
    static ThreadLocal<Person> threadLocal  = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(()->{
           Person person = new Person("dwa",123);
           threadLocal.set(person);
        }).start();
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println( threadLocal.get().toString());

        }).start();
    }
/*    volatile static Person person  = new Person("李四",15);

    public static void main(String[] args) {
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("person = " + person.getName());
        }).start();

        new Thread(()->{

            person.setName("王五");
        }).start();

    }*/
}
